package com.learn.springcloud.hystrixquickstart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Time : 2018/7/25 20:13
 * @Version : 1.0
 * @Author : hongyan.li@hand-china.com
 * Copyright @ 2000 Shanghai Hand Co. Ltd.
 * All right reserved.
 */
@RestController
public class Consumer {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private LoadBalancerClient loadBalancerClient;


    @RequestMapping("/consumer/file/config")
    public String fileConfig(){
        String result = "";
        ServiceInstance serviceInstance1 = loadBalancerClient.choose("ribbon-coding-config-provider-group1");
        ServiceInstance serviceInstance2 = loadBalancerClient.choose("ribbon-coding-config-provider-group2");
        ServiceInstance serviceInstance3 = loadBalancerClient.choose("ribbon-coding-config-provider-group3");

        System.out.println(serviceInstance1);
        System.out.println(serviceInstance2);
        System.out.println(serviceInstance3);

        result = serviceInstance1.toString() + "\n" + serviceInstance2.toString() + "\n" + serviceInstance3.toString();

        return result;
    }

}
